/**
 * Description:Used for retrieval of description of a particular post
 * Request:Home.jsp
 * Response:PostDescription.jsp
 */
package com.actions;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JOptionPane;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.DAO.*;
import com.beans.*;
public class TitleDescriptionAction  extends org.apache.struts.action.Action{

	private final static String SUCCESS = "success";
    
    
	 public ActionForward execute(ActionMapping mapping, ActionForm form,
	            HttpServletRequest request, HttpServletResponse response)
	            throws Exception {
	    	
	    	NoticeForm noticeForm=(NoticeForm)form;
	    	int id=1;
	    	try{
	    	if(request.getParameter("noticeid")!=null){	
	    	id=Integer.parseInt(request.getParameter("noticeid"));
	    	System.out.println("Notice id is...."+id);
	    	}
	    		
	    	}
	    	catch(NumberFormatException e){
	    		System.out.println("id is not found........");
	    	}
	    	
	    	NoticeDAO noticeDao=new NoticeDAO();
	    	
	    	noticeForm=noticeDao.getNoticeById(id);
	    	
	    	HttpSession session=request.getSession();
	    	
	    	session.setAttribute("noticeform", noticeForm);
	    	
	    	ArrayList<CommentForm> listComments =new ArrayList<CommentForm>();
	    	
	    	listComments=noticeDao.getComments(id);
	    	
	    	session.setAttribute("listComments", listComments);
	    	
			//noticeDao.closeConnection();
			return mapping.findForward(SUCCESS);
			
		}
}